//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"
// 定义枚举
enum DaysofaWeek {
    case Sunday
    case Monday
    case TUESDAY
    case WEDNESDAY
    case THURSDAY
    case FRIDAY
    case Saturday
}

var weekDay = DaysofaWeek.THURSDAY
weekDay = .THURSDAY
switch weekDay
{
case .Sunday:
    print("星期天")
case .Monday:
    print("星期一")
case .TUESDAY:
    print("星期二")
case .WEDNESDAY:
    print("星期三")
case .THURSDAY:
    print("星期四")
case .FRIDAY:
    print("星期五")
case .Saturday:
    print("星期六")
}

enum Student {
    case Name(String)
    case Mark(Int,Int,Int)
}

var studDetails = Student.Name("Runoob")
var studMarks = Student.Mark(98,97,95)

switch studMarks {
case .Name(let studName):
    print("学生的名字是: \(studName)。")
case .Mark(let Mark1, let Mark2, let Mark3):
    print("学生的成绩是: \(Mark1),\(Mark2),\(Mark3)。")
}

enum Month: Int {
    case January = 1, February, March, April, May, June, July, August, September, October, November, December
}

let yearMonth = Month.May.rawValue
print("yearMonth = \(yearMonth)")

struct MarkStruct {
    var mark1: Int
    var mark2: Int
    var mark3: Int
}

struct studentMarks {
    var mark1 = 100
    var mark2 = 78
    var mark3 = 98
}
let marks = studentMarks()
print("Mark1 是 \(marks.mark1)")
print("Mark2 是 \(marks.mark2)")
print("Mark3 是 \(marks.mark3)")


class SampleClass: NSObject {
    let myProp: String
    init(s: String) {
        myProp = s
    }
}

func ==(lhs: SampleClass, rhs: SampleClass) -> Bool {
    return lhs.myProp == rhs.myProp
}

let spClass1 = SampleClass(s: "Hello")
let spClass2 = SampleClass(s: "Hello")

if spClass1 === spClass2 {// false
    print("引用相同的类实例 \(spClass1)")
}

if spClass1 !== spClass2 {// true
    print("引用不相同的类实例 \(spClass2)")
}


struct area {
    var length = 1
    var breadth = 1
    func area() -> Int {
        return length * breadth
    }
    
    // 实例方法中修改属性值，需要标记为mutating
    mutating func scaleBy(res: Int) {
        length *= res
        breadth *= res
        
        print("length = \(length)  breadth = \(breadth)")
    }
    
    subscript(index: Int) -> Int {
        return 1;
    }
    
    
}

var val = area(length: 3, breadth: 3)
val.scaleBy(res: 4)
print(val[1])


class dayofweak {
    private var days = ["Sunday", "Monday", "Tuesday", "Wednesday",
                        "Thursday", "Friday", "saturday"]
    
    subscript(index: Int) -> String {
        get {
            return days[index]   // 声明下标脚本的值
        }
        set(newValue) {
            self.days[index] = newValue   // 执行赋值操作
        }
    }
}

// 类的构造器
class mainClass {
    var no1: Int
    var no2: Int
    init(no1: Int, no2: Int) {
        self.no1 = no1
        self.no2 = no2
    }
    
    init(no2: Int) {
        self.no2 = no2
        self.no1 = 0
    }
    
    // 便利构造器调用指定构造器
    convenience init(no1: Int) {
        self.init(no1: no1, no2: 0)
    }
    
}

// 构造器的继承
class subClass : mainClass {
    var no3:Int
    
    init(no1: Int, no2: Int, no3: Int) {
        self.no3 = no3
        super.init(no1: no1, no2: no2)
    }
    
    convenience init(no3: Int) {
//        self.no3 = no3
        // convenience initializer for 'subClass' must delegate (with 'self.init') rather than chaining to a superclass initializer (with 'super.init')
        // 便利构造器只能调用本类的指定构造器，而不能调用父类的构造器
//        super.init(no1: 0, no2: 0)
        self.init(no1: 0, no2: 0, no3: no3)
    }
}


// 构造器的重载
class Shape {
    var corner : Int = 0
}

class Circle : Shape {
    var radius : Int
    override init() {
        self.radius = 10
        super.init()
        super.corner = 1
    }

    init(radius: Int) {
        self.radius = radius
    }
}

var cir = Circle()
print("circle radius = \(cir.radius)")

